import com.mysql.cj.jdbc.ConnectionImpl;

import java.sql.*;

/**
 * @author: knowno
 * @create: 2025-09-18 09:04
 * @Version 1.0
 **/
public class TestJDBC1 {
    public static void main(String[] args) {

        try {
            //1.加载驱动(适用于低版本 mysql5.x) 如果是8+ 则不需要 ,is automatically registered via the SPI
//            Class.forName("com.mysql.jdbc.Driver");
            //2.获取连接  Connection ->java.sql.Connection是一个接口
            //DriverManager.getConnection 对应的实际类型是 com.mysql.cj.jdbc.ConnectionImpl
                    // com.mysql.cj.jdbc.ConnectionImpl
            //public class ConnectionImpl implements JdbcConnection
                    //public interface JdbcConnection extends java.sql.Connection
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/hisdb2", "root", "root");
            System.out.println(conn.getClass());
            //3.获取语句执行平台
            String sql = "insert into role values(null,'test1111111','test1111111')";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            System.out.println(pstmt);
            //4.执行SQL语句 =>增加 删除和的修改 executeUpdate
            int i = pstmt.executeUpdate();
            System.out.println(i);
            //5.关闭资源
            pstmt.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
